import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'node:path';

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],

  // 路径别名设置
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },

  // 通过服务代理实现跨域
  server: {
    host: '0.0.0.0',
    port: 5173,
    strictPort: true,
    open: true,
    proxy: {
      '/api': {
        // 服务器项目的访问地址 localhost、127.0.0.1
        target: 'http://localhost:8080',
        changeOrigin: true,
        // 替换 /api => springboot => application.yml
        // server.servlet.context-path
        rewrite: (path) => path.replace(/^\/api/, 'api')
      }
    }
  }
});
